#include "unp.h"

ssize_t Writen(int fd, const void* vptr, size_t n)
{
    size_t nleft, nwrite;
    const char *ptr = vptr;

    nleft = n;
    while (nleft > 0) {
        if ( (nwrite=write(fd, ptr, nleft)) <= 0) {
            if (nwrite<0 && errno==EINTR) {
                nwrite = 0;
            } else {
                return -1;
            }
        }
        nleft -= nwrite;
        ptr += nwrite;
    }
    return n; /* XXX */
}

